package com.ruoyi.front.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.front.domain.Work;
import com.ruoyi.front.dto.WorkDTO;
import com.ruoyi.front.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("front")
public class WorkController {
    @Autowired
    private WorkService workService;
    @PostMapping("/upload")
    public R uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        String url = FileUploadUtils.upload(file);
        return R.ok(url);
    }
    //填写作品信息
    @PostMapping("work")
    public R add(@RequestBody WorkDTO workDTO){
        return workService.add(workDTO);
    }

    //获取作品相关信息
    @GetMapping("work/{id}")
    public R getWorkById(@PathVariable Integer id){
        return workService.getWorkById(id);
    }
}